#include <iostream>

using namespace std;

typedef long long LL;

const int N = 2e5 + 10;
LL n, a[N];

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] = a[i - 1] + a[i];
	}
	LL ret = -1e17;
	LL prevmin = a[1];
	for(int i = 1; i <= n; i++)
	{
		ret = max(ret, a[i] - prevmin);
		prevmin = min(prevmin, a[i]);
	}
	cout << ret << endl;
	return 0;
} 
